package cn.stylefeng.guns.modular.storage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.storage.entity.StorageStockDetailed;
import cn.stylefeng.guns.modular.storage.model.params.StorageOutDetailedParam;
import cn.stylefeng.guns.modular.storage.model.params.StoragePutSingleParam;
import cn.stylefeng.guns.modular.storage.model.params.StorageStockDetailedParam;
import cn.stylefeng.guns.modular.storage.service.StorageOutDetailedService;
import cn.stylefeng.guns.modular.storage.service.StoragePutSingleService;
import cn.stylefeng.guns.modular.storage.service.StorageStockDetailedService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 库存流水控制器
 */
@Controller
@RequestMapping("/storageStockDetailed")
public class StorageStockDetailedController extends BaseController {

    private String PREFIX = "/storage/storageStockDetailed";

    @Autowired
    private StorageStockDetailedService storageStockDetailedService;
    
    @Autowired
    private StoragePutSingleService storagePutSingleService;
    
    @Autowired
    private StorageOutDetailedService storageOutDetailedService;

    @Autowired
    private UserService userService;

    /**
     * 入库单明细页面
     */
    @RequestMapping("toPut")
    public String toPut() {
        return PREFIX + "/storagePutSingle.html";
    }

    /**
     * 查询入库单明细列表
     */
    @ResponseBody
    @RequestMapping("/putlist")
    public LayuiPageInfo putlist(StoragePutSingleParam storagePutSingleParam,String condition ) {
        return this.storagePutSingleService.findPageBySpec(storagePutSingleParam,condition);
    }

    /**
     * 出库单明细页面
     */
    @RequestMapping("toOut")
    public String toOut() {
        return PREFIX + "/storageOutDetailed.html";
    }

    /**
     * 查询出库记录
     */
    @ResponseBody
    @RequestMapping("/outlist")
    public LayuiPageInfo outlist(StorageOutDetailedParam storageOutDetailedParam,String condition) {
    	return this.storageOutDetailedService.findPageBySpec(storageOutDetailedParam,condition);
    }

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/storageStockDetailed.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/storageStockDetailed_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/storageStockDetailed_edit.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(StorageStockDetailedParam storageStockDetailedParam) {
        this.storageStockDetailedService.add(storageStockDetailedParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(StorageStockDetailedParam storageStockDetailedParam) {
        this.storageStockDetailedService.update(storageStockDetailedParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(StorageStockDetailedParam storageStockDetailedParam) {
        this.storageStockDetailedService.delete(storageStockDetailedParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(StorageStockDetailedParam storageStockDetailedParam) {
        StorageStockDetailed detail = this.storageStockDetailedService.getById(storageStockDetailedParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(StorageStockDetailedParam storageStockDetailedParam,String condition ) {
        return this.storageStockDetailedService.findPageBySpec(storageStockDetailedParam,condition);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/listGoods")
    public LayuiPageInfo listGoods(StorageStockDetailedParam storageStockDetailedParam,String condition,String startTime,String endTime ) {
    	if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
    		storageStockDetailedParam.setMoney("'"+startTime+"' and '"+endTime+"'");
    	} 
        return this.storageStockDetailedService.findPageByGoodsSpec(storageStockDetailedParam,condition);
    }

}


